//
//  ViewController.m
//  Line_fall
//
//  Created by zpy on 15/12/2.
//  Copyright © 2015年 zpy. All rights reserved.
//

#import "ViewController.h"
#import "PYLineCell.h"
#import "PYLineLayout.h"

@interface ViewController ()<UICollectionViewDataSource,UICollectionViewDelegate>
// 所有的图片名
@property (nonatomic, strong) NSMutableArray *images;
@property (nonatomic, weak) UICollectionView *collectionView;
@end

@implementation ViewController

static NSString *const ID = @"image";
-(NSMutableArray *)images{
    if (!_images) {
        self.images = [[NSMutableArray alloc] init];
        for (int i = 1; i <= 20; i ++) {
            [self.images addObject:[NSString stringWithFormat:@"%d",i]];
        }
    }
    return _images;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    CGFloat w = self.view.frame.size.width;
    CGRect rect = CGRectMake(0, 170, w, 200);
    
    // UICollectionViewLayout
    // UICollectionViewFlowLayout
    
    // 创建布局
    PYLineLayout *layout = [[PYLineLayout alloc] init];
    
    // 创建CollectionView
    UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:rect collectionViewLayout:layout];
    collectionView.dataSource = self;
    collectionView.delegate = self;
    [collectionView registerNib:[UINib nibWithNibName:@"PYLineCell" bundle:nil] forCellWithReuseIdentifier:ID];
    [self.view addSubview:collectionView];
    self.collectionView = collectionView;
    
    
}
#pragma mark - <UICollectionViewDataSource>
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.images.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    PYLineCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath];
    //    cell.backgroundColor = [UIColor redColor];
    cell.image = self.images[indexPath.item];
    return cell;
}

#pragma mark - <UICollectionViewDelegate>
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
}


@end
